﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace dzs.Web
{
    /// <summary>
    /// GetMaterialInfo 获取物料信息
    /// </summary>
    public class GetMaterialInfo : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string keyword = context.Request.QueryString["keyword"];
            if (keyword != null)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                // 通过JavaScriptSerializer对象的Serialize序列化为["value1","value2",...]的字符串    
                string jsonString = serializer.Serialize(GetFilteredList(keyword));
                context.Response.Write(jsonString); // 返回客户端json格式数据       
            }
        }
        private string[] GetFilteredList(string keyword)
        {
            dzs.BLL.materialinfo bll = new BLL.materialinfo();
            DataSet ds = bll.GetMaterial(" material like '%" + keyword + "%'");

            List<string> proList = new List<string>();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                //此处选项一般从数据库中读取，然后循环添加给countrylist对象即可。
                proList.Add(ds.Tables[0].Rows[i]["material"].ToString());
            }

            return proList.ToArray();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}